<?php
namespace houze\shop;
use houze\shop\lib\Client;

/**
 * 订单类
 */
class Order extends Client{
    // 订单列表
    public function list(){
        if(empty($this->key) || empty($this->value)) return $this->db->table($this->table)->select();
        return $this->db->table($this->table)->where($this->key, $this->value)->select();
    }

    // 订单查询
    public function find(){
        return $this->db->table($this->table)->where($this->key, $this->value)->find();
    }

    // 订单添加
    public function add(){
        try {
            $this->db->table($this->table)->insert($this->data);
            // 提交事务
            $this->commit();
            return true;
        } catch (\Exception $e) {
            // 回滚事务
            $this->rollback();
            return false;
        }
    }

    // 订单修改
    public function update(){
        try {
            $this->db->table($this->table)->where($this->key, $this->value)->update($this->data);
            // 提交事务
            $this->commit();
            return true;
        } catch (\Exception $e) {
            // 回滚事务
            $this->rollback();
            return false;
        }
    }

    // 订单删除
    public function delete(){
        try {
            $this->db->table($this->table)->where($this->key, $this->value)->delete();
            // 提交事务
            $this->commit();
            return true;
        } catch (\Exception $e) {
            // 回滚事务
            $this->rollback();
            return false;
        }
    }
}